package com.uphone.kingmall.adapter;

import android.content.Context;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.SizeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.china.zhuoyue.R;
import com.luck.picture.lib.entity.LocalMedia;
import com.uphone.kingmall.utils.GlideUtils;

import java.util.List;

/**
 * <pre>
 *     author : 孙增艳
 *     e-mail : sunzengyan@outlook.com
 *     time   : 2019/2/26
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public class RvUpLoadImageAdapter0 extends BaseQuickAdapter<LocalMedia, BaseViewHolder> {
    private final Context context;

    public RvUpLoadImageAdapter0(Context context, @Nullable List<LocalMedia> data) {
        super(R.layout.kingmall_item_rv_upload_image, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, LocalMedia item) {
        ImageView imageView = helper.getView(R.id.iv_image);

        if (getData() == null || getData().size() == 0 || getData().size() == helper.getLayoutPosition()) {
            GlideUtils.getInstance().loadPathImage(context, R.mipmap.upload_image, imageView);
        } else{
            String path = item.getPath();
            GlideUtils.getInstance().loadCornerImage(context, path, SizeUtils.dp2px(2), imageView);
        }

    }

    @Override
    public int getItemCount() {
        return getData() == null ? 1 : getData().size() + 1;
    }
}
